﻿<?php require_once('Connections/satphp.php'); ?>
<?php

function erro(){include "error-page.html";};

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$idturma = @$_GET['idturma'];
$idaula = @$_GET['idaula'];


if (isset($_POST['envia'], $idturma, $idaula) && $idturma !="" && $idaula != "")
{
	$qtd = $_POST['qtd'];
	for($i = 1; $i <= $qtd; $i++ ){
		$presenca = "presenca".$i;
		 
		if (@isset($_POST["$presenca"]))$pre = $_POST["$presenca"]; else $pre = 0; 
		$aluno = "idaluno".$i;
		$alu = $_POST["$aluno"];
			
			mysql_select_db($database_satphp, $satphp);
			$query_Recordset1 = "INSERT INTO presenca
								 (idaluno, idaula, presencas)
								 VALUES ( $alu, $idaula, $pre )";
			$Recordset1 = mysql_query($query_Recordset1, $satphp) or die(mysql_error());
	}
}

if (isset($idturma, $idaula))
{
	mysql_select_db($database_satphp, $satphp);
	$query_Recordset1 = "SELECT aluno.idaluno, 
								aluno.nome
						FROM aluno 
						LEFT JOIN turma 
							ON ( aluno.idturma = turma.idturma )
						LEFT JOIN disciplina 
							ON ( disciplina.idturma = turma.idturma )
						WHERE aluno.idturma = $idturma
						ORDER BY aluno.nome";
	$Recordset1 = mysql_query($query_Recordset1, $satphp) or die(mysql_error());
	$row_Recordset1 = mysql_fetch_assoc($Recordset1);
	$totalRows_Recordset1 = mysql_num_rows($Recordset1);
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Presença | SATPHP</title>
</head>

<body>
<form method="POST" action="presenca-registrar.php?idturma=<?php echo $idturma; ?>&idaula=<?php echo $idaula; ?>" onmouseover="document.getElementById('envia').value='true'">
<table align="center" width="568" border="1">
	<tr>
    	<td colspan="4" align="center"><strong>Lista de Chamada</strong></td>
    </tr>
  <tr>
    <td width="15"><strong>Nº</strong></td>
    <td width="100%"><strong>Nome</strong></td>
    <td width="20" align="center">P</td>
    <td width="20" align="center">F<input type="hidden" name="envia" id="envia" /></td>
  </tr>
  <?php $id=1; do { ?>
    <tr>
      <td><?php echo "$id"; ?></td>
        <td><?php echo $row_Recordset1['nome']; ?><input type="hidden" name="idaluno<?php echo $id; ?>" value="<?php echo $row_Recordset1['idaluno']; ?>" /></td>
        
        <td align="center"><input id="p<?php echo $id; ?>" name="presenca<?php echo $id; ?>" value="1" type="radio" /></td>
        <td align="center"><input id="f<?php echo $id; ?>" name="presenca<?php echo $id; ?>" value="0" type="radio" /></td>
    </tr>
    <?php $id++;} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));?>
    <tr>
      <td colspan="2">P = Presença, F = Falta<input type="hidden" name="qtd" id="qtd" value=<?php echo $id-1; ?> /></td>
      <td colspan="2"><input type="submit" value="Salvar" /></td>
    </tr>
</table>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);} else { erro();}
?>
